package com.zhss.demo.redisson.lock;

import com.zhss.demo.ConsolHelp;
import com.zhss.demo.redisson.RedissionHelp;
import org.redisson.api.RReadWriteLock;
import org.redisson.api.RedissonClient;

public class MultiLockDemo {
    public static void main(String[] args) throws InterruptedException {
        RedissonClient redissionClient = RedissionHelp.getRedissionClient();
        RReadWriteLock rwlock = redissionClient.getReadWriteLock("anyRWLock");

        Runnable runnable = new Runnable() {
            @Override
            public void run() {
                rwlock.readLock().unlock();
            }
        };
        Thread t1 = new Thread(runnable);
        Thread t2 = new Thread(runnable);
        Thread t3 = new Thread(runnable);

        t1.start();
        t2.start();
        t3.start();

        t1.join();
        t2.join();
        t3.join();


        while (true) {
            String command = ConsolHelp.get();
            if ("close".equals(command)) {
                break;
            } else {
                System.err.println(command);
            }
        }
        RedissionHelp.shutdown(redissionClient);
    }
}
